package com.automation.fitness.core.plan;

import com.automation.fitness.core.workout.Workout;
import lombok.Getter;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 记录每天训练情况、完成度
 */
@Getter
public class DailyPlan {
    // 计划消耗卡路里
    private final double expectedCalories;

    // 今日训练计划
    private final List<Workout> workouts;

    // 今日日期
    private final LocalDate date;

    // 今日实际消耗卡路里
    private final double actualCalories;

    // 今日完成度
    private final double completedPct;

    public DailyPlan(double expectedCalories, List<Workout> workouts, LocalDate date) {
        this.expectedCalories = expectedCalories;
        this.workouts = workouts;
        this.actualCalories = workouts.stream().mapToDouble(Workout::calcCalories).sum();
        this.completedPct = expectedCalories == 0 ? 100 : (actualCalories / expectedCalories) * 100;
        this.date = date;
    }

    public List<Workout> getWorkouts() {
        ArrayList<Workout> copy = new ArrayList<>(this.workouts.size());
        Collections.copy(copy, this.workouts);
        return copy;
    }

    public static DailyPlan newInstance(double expectedCalories, List<Workout> workouts) {
        return new DailyPlan(expectedCalories, workouts, LocalDate.now());
    }

    public static DailyPlan parse(String data) {
        return null;
    }
}
